package de.tum.in.elitese.wahlsys.common;

import java.util.List;

import de.tum.in.elitese.wahlsys.common.data.PartyNumber;
import de.tum.in.elitese.wahlsys.common.data.PartyTicket;
import de.tum.in.elitese.wahlsys.common.data.Person;
import de.tum.in.elitese.wahlsys.common.data.RegionalInformation;
import de.tum.in.elitese.wahlsys.common.data.UserCredentials;
import de.tum.in.elitese.wahlsys.common.data.ValidationEnum;

/**
 * This is a common interface for necessary queries against the data source.
 * Implementors could be e.g. a web service client or a class connecting to the
 * data base using JDBC.
 * 
 * @author christoph
 * 
 */
public interface DbService {

	/**
	 * Checks whether the given ID number and password are valid.
	 * 
	 * @param idNumber
	 *            the id number
	 * @param password
	 *            the password
	 * @return a ValidationEnum entity indicatiting the result of the
	 *         validationing process
	 * @throws KnownExecption
	 */
	public abstract ValidationEnum checkIsIdNumberAndPasswordValid(Integer idNumber, String password) throws KnownExecption;

	/**
	 * Gathers all direct candidates for a electoral district and state.
	 * 
	 * @param electoral
	 *            district
	 * @param state
	 * @return a list of the direct candidates
	 * @throws KnownExecption
	 */
	public abstract List<Person> getDirectCandidates(int electoralDistrict, String state) throws KnownExecption;

	/**
	 * Gathers all elected members of the parliament
	 * 
	 * @return a list of the members
	 * @throws KnownExecption
	 */
	public abstract List<Person> getMembersOfParliament() throws KnownExecption;

	/**
	 * Gathers the elected members of the parliament for a given state
	 * 
	 * @param state
	 *            the name of the state
	 * @return a list of the members
	 * @throws KnownExecption
	 */
	public abstract List<Person> getMembersOfParliament(String state) throws KnownExecption;

	/**
	 * Gathers the parties and the according number of seats in the parliament.
	 * 
	 * @return a list of the PartyNumber wrapper objects
	 * @throws KnownExecption
	 */
	public abstract List<PartyNumber> getPartySeatsList() throws KnownExecption;

	/**
	 * Gathers the parties and the according number of seats in the parliament
	 * for a given state
	 * 
	 * @param state
	 *            the name of the state
	 * @return a list of the members
	 * @throws KnownExecption
	 */
	public abstract List<PartyNumber> getPartySeatsList(String state) throws KnownExecption;

	/**
	 * Gathers all party tickets for a state
	 * 
	 * @param state
	 * @return a list of the party tickets
	 * @throws KnownExecption
	 */
	public abstract List<PartyTicket> getPartyTicketList(String state) throws KnownExecption;

	/**
	 * Gathers the share of votes for the parties of the parliament
	 * 
	 * @return a list of the PartyNumber wrapper objects
	 * @throws KnownExecption
	 */
	public abstract List<PartyNumber> getPartyVotesList() throws KnownExecption;

	/**
	 * Gathers the share of votes for the parties of the parliament for a given
	 * state
	 * 
	 * @param state
	 *            the name of the state
	 * @return a list of the members
	 * @throws KnownExecption
	 */
	public abstract List<PartyNumber> getPartyVotesList(String state) throws KnownExecption;

	/**
	 * Searches for a person for the given ID number
	 * 
	 * @param idNumber
	 * @return the person, or null if non was found
	 * @throws KnownExecption
	 */
	public abstract Person getPerson(int idNumber) throws KnownExecption;

	/**
	 * Queries the Regional Information for the given ID number of a voter.
	 * 
	 * @param IdNumber
	 *            of the voter
	 * @return the RegionalInformation, or null if no where found.
	 * @throws KnownExecption
	 */
	public abstract RegionalInformation getRegionalInformation(Integer IdNumber) throws KnownExecption;

	public abstract List<String> getStateList() throws KnownExecption;

	/**
	 * Gathers the UserCredentials for a given name and password combination.
	 * 
	 * @param name
	 * @param password
	 * @return the UserCrednetials, or null if non was found
	 * @throws KnownExecption
	 */
	public abstract UserCredentials getUserCredentials(String name, String password) throws KnownExecption;

	/**
	 * Performes the analysis of the election and thus determines the members of
	 * the parliament
	 * 
	 * @throws KnownExecption
	 */
	public abstract void performElectionAnalysis() throws KnownExecption;

	/**
	 * Sets a voting paper to be used and thus invalidates it.
	 * 
	 * @param idNumber
	 *            of the voter
	 * @param password
	 *            of the voting paper
	 * @throws KnownExecption
	 */
	public abstract void setWahlscheinAsUsed(Integer idNumber, String password) throws KnownExecption;

}